<?php
namespace app\home\controller;
class Index extends Common{
    public function _initialize(){
        parent::_initialize();
    }
    public function index(){
        return $this->fetch();
    }
    public function  search(){
        //传入查询类型
        $category = input('category');
        //传入查询关键字
        $keywords = input('keywords');
        //根据传入的类型判断需要查询的数据库表
        if($category == 'article') {
            $list = db('article')->alias('a')
                ->join(config('database.prefix') . 'category c', 'a.catid = c.id', 'left')
                ->field('a.*,c.catdir')
                ->where('a.title', 'like', '%' . $keywords . '%')
                ->order('a.id desc')
                ->paginate(5, false, $config = ['query' => array('category' => $category, 'keywords' => $keywords)]);
            $page = $list->render();
            $list = $list->toArray();
            foreach ($list['data'] as $k=>$v){
                $list['data'][$k]['controller'] = $v['catdir'];
                $list_style = explode(';',$v['title_style']);
                $list['data'][$k]['title_color'] =$list_style[0];
                $list['data'][$k]['title_weight'] =$list_style[1];
                $title_thumb = $v['thumb'];
                $list['data'][$k]['title_thumb'] = $title_thumb?__PUBLIC__.$title_thumb:config('view_replace_str.__HOME__').'/images/portfolio-thumb/p'.($k+1).'.jpg';
            }
            $this->assign(['page'=>$page,
                           'list'=>$list['data'],
                           'keywords'=>$keywords]);
            return view('search_list');
        }else if($category == 'case'){
            // $serRes = db('case');
        }else{
            // ...
        }
        return  null;
      }
}